//
//  TestViewController.m
//  Rac
//
//  Created by ios on 2017/3/22.
//  Copyright © 2017年 Wy. All rights reserved.
//

#import "TestViewController.h"
#import "TableView.h"
#import "ViewModel.h"

@interface TestViewController ()

@property(nonatomic,strong) TableView *tableView;
@property(nonatomic,strong) ViewModel *viewModel;

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.viewModel = [ViewModel new];
    
    [self bindViewModel];
    
    [self.view addSubview:self.tableView];
    
}

-(void)bindViewModel{
    
    //KVO 形式  动态监测 数组和 页数
    RAC(self.tableView,dataArray) = RACObserve(self.viewModel, self.data);
    RAC(self.tableView,page)      = RACObserve(self.viewModel, self.page);
    
    [self.viewModel.refreshCommand execute:@[self.tableView,@(1)]];
}

-(TableView*)tableView{

    if (!_tableView) {
        _tableView = [[TableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        
        _tableView.viewModel = self.viewModel;
        
    }
    return _tableView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
